<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <title>专业类别选择组件</title>
    <meta name='renderer' content='webkit|ie-comp|ie-stand'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <meta name='viewport'
          content='width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0'>
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel='shortcut icon' href='../../../favicon.ico' type='image/x-icon'/>
    <link rel='stylesheet' href='../../../static/css/font.css'>
    <link rel='stylesheet' href='../../../static/css/weadmin.css'>
    <link rel="stylesheet" href="../../../lib/jqueryZtree/3.5.12/css/zTreeStyle/zTreeStyle.css">
    <link rel='stylesheet' href='../../../static/css/buildUnit/common.css'>
    <script type='text/javascript' src='/lib/layui/layui.js' charset='utf-8'></script>
    <script src="/lib/jquery/jquery.js"></script>
    <script src="/lib/jqueryZtree/3.5.12/js/jquery.ztree.all-3.5.js"></script>
</head>
<body>
<div class='content'>
    <div id='templateId' class="ztree"></div>
    <input type="hidden" name="chooseMajor"/>
    <input type="hidden" id="btnSubmit"/>
</div>
<script src='../../../static/js/main.js'></script>
<script type='text/javascript'>
    layui.use(['permission', 'bluebird', 'configureCom', 'jquery', 'tree', 'sessionFun', 'jsDictFile', 'ztree'], function () {
        var $ = layui.$;
        var jsDictFile = layui.jsDictFile;
        var sessionFun = layui.sessionFun;
        var ztree = layui.ztree;
        var professionalCategory = {
            data: {
                value: 0,
                name: '专业工程分类',
                childrens: jsDictFile.sgProjSpecType,
                major: []
            },
            dataPrepare: function (dataNode, pid) {
                professionalCategory.data.major.push({
                    id: dataNode.value,//当前节点ID
                    pId: pid,//父节点ID
                    pid: pid,//父节点value值
                    name: dataNode.name
                });
                if (dataNode.childrens && dataNode.childrens.length > 0) {
                    $(dataNode.childrens).each(function (index, item) {
                        professionalCategory.dataPrepare(item, dataNode.value);
                    });
                }
            },
            render: function () {
                professionalCategory.dataPrepare(professionalCategory.data, 0);
                ztree.param.idKey = 'id';
                ztree.param.pIdKey = 'pId';
                ztree.param.rootPId = "0";
                ztree.param.multiCheck = false;
                ztree.param.onClick = function (event, treeId, treeNode) {
                    if (!treeNode.isParent) {
                        $('input[name=chooseMajor]').val(JSON.stringify(treeNode));
                    }
                };
                ztree.init('templateId', '专业工程分类', professionalCategory.data.major);
            },
            eventBind: function () {
                $('#btnSubmit').click(function () {
                    if ($('input[name=chooseMajor]').val() !== '') {
                        window.parWin.saveForm($('input[name=chooseMajor]').val());
                    }
                    else {
                        top.layer.alert('请选择专业类别');
                    }
                });
            }
        };
        professionalCategory.render();
        professionalCategory.eventBind();
    });
</script>
</body>
</html>